package nsu.edu.zsq.controller.student;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;

import nsu.edu.zsq.bean.StuCourse;
import nsu.edu.zsq.common.JsonData;
import nsu.edu.zsq.param.PageQuery;
import nsu.edu.zsq.param.TchCourseParam;
import nsu.edu.zsq.service.student.CourseManagerService;

/** 
* Description: 学生课程管理的controller类<br>
*/
@RequestMapping("/student/course")
@Controller
public class CourseManagerController {
    
    @Autowired
    private CourseManagerService courseManagerService;
    
    /**
     * 跳转到学生的学期课表页面,携带课表信息
     * @param model
     * @return String student/course/stuCourse_list.html
     */
    @RequestMapping("/toStuCourse_list")
    public String toStuCourse_list(Model model) {
        List<StuCourse> listStuCourse = courseManagerService.listStuCourse();
        model.addAttribute("listStuCourse", listStuCourse);
        return "student/course/stuCourse_list.html";
    }

    // ===========================================网上选课===========================================
    
    /**
     * 获取该学生所在专业的专业选修课+公共选修课
     * @return JsonData
     */
    @RequestMapping("/listTchCourse")
    @ResponseBody
    public JsonData listTchCourse(PageQuery pageQuery) {
        PageInfo<TchCourseParam> listTchCourse = courseManagerService.listTchCourse(pageQuery);
        return JsonData.success(listTchCourse);
    }
    
    /**
     * 学生选课
     * @param tchCourseId 教师课程id
     * @return JsonData
     */
    @RequestMapping("/chooseCourse")
    @ResponseBody
    public JsonData chooseCourse(@RequestParam("tchCourseId")int tchCourseId) {
        courseManagerService.chooseCourse(tchCourseId);
        return JsonData.success();
    }
    
    // ===========================================选课结果===========================================
    
    /**
     * 获取该学生的选修课程列表
     * @return JsonData
     */
    @RequestMapping("/listStuCourse")
    @ResponseBody
    public JsonData listStuCourse() {
        List<HashMap<String, String>> listStuCourseByStuNo = courseManagerService.listStuChooseCourse();
        return JsonData.success(listStuCourseByStuNo);
    }
    
    /**
     * 退选一个课程
     * @param stuCourseId 学生课程id
     * @return JsonData
     */ 
    @RequestMapping("/removeChooseCourse")
    @ResponseBody
    public JsonData removeChooseCourse(@RequestParam("stuCourseId")int stuCourseId) {
        courseManagerService.removeChooseCourse(stuCourseId);
        return JsonData.success();
    }
}
